<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title th:text="${appName}"></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->

    <link href="../images/favicon.ico" rel="shortcut icon"/>
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="../js/layui/css/layui.css" rel="stylesheet" media="all">
    <link href="../js/jquery-showLoading/showLoading.css" rel="stylesheet" media="screen"/>
    <script src="../inc/common.js"></script>
    <!--<script src="js/jquery.min.js?v=2.1.4"></script>-->
    <script src="../js/jquery-1.9.1.min.js"></script>
    <script src="../js/jquery-migrate-1.2.1.min.js"></script>
    <link href="../js/jquery-alerts/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />
    <script src="../js/jquery-alerts/jquery.alerts.js" type="text/javascript"></script>
    <script src="../js/jquery-alerts/cws.alerts.js" type="text/javascript"></script>
    <script src="../js/layui/layui.js" charset="utf-8"></script>
    <script src="../js/jquery-showLoading/jquery.showLoading.js"></script>
</head>
<body class="fixed-sidebar full-height-layout gray-bg" style="overflow:hidden">
<div id="wrapper">
    <!--左侧导航开始-->
    <nav class="navbar-default navbar-static-side" th:style="${isMenuDisplay ? '' : 'display:none'}" role="navigation">
        <div class="nav-close"><i class="fa fa-times-circle"></i>
        </div>
        <div class="sidebar-collapse">
            <ul class="nav" id="side-menu">
                <li class="nav-header">
                    <div class="dropdown profile-element">
                        <span>
                            <img class="img-circle" th:src="@{'/' + ${portrait}}"/>
                        </span>
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <span class="clear">
                            <span class="block m-t-xs"><strong class="font-bold" th:text="${user.realName}"></strong></span>
                            <span class="text-muted text-xs block">个人信息<b class="caret"></b></span>
                            </span>
                        </a>
                        <ul class="dropdown-menu animated fadeInRight m-t-xs">
                            <th:block th:if="${isRoleSwitchable}" th:each="role, stat : ${roleList}">
                                <li><a href="javascript:;" th:onclick="switchRole('[(${role.code})]')">[[#{role}]]：[[${role.description}]]<i th:if="${role.code eq curRoleCode}" class="fa fa-check" style="font-size: 12px; margin-left: 10px; color: #77cc77"></i></a></li>
                            </th:block>
                            <li class="divider" th:if="!${#lists.isEmpty(roleList)}"></li>
                            <th:block th:if="${isDeptSwitchable}" th:each="dept, stat : ${deptList}">
                                <li><a href="javascript:;" th:onclick="switchDept('[(${dept.code})]')">[[#{dept}]]：[[${dept.name}]]<i th:if="${dept.code eq curDeptCode}" class="fa fa-check" style="font-size: 12px; margin-left: 10px; color: #77cc77"></i></a></li>
                            </th:block>
                            <li class="divider" th:if="!${#lists.isEmpty(deptList)}"></li>

                            <th:block th:switch="${isArchiveShowAsUserInfo}">
                                <li th:case="true"><a class="J_menuItem" th:href="@{'/visual/moduleShowPage.do?moduleCode=personbasic&id=' + ${personId} + '&visitKey=' + ${personVisitKey}}">个人资料</a></li>
                                <li th:case="*"><a class="J_menuItem" href="../user/editUser.do">个人资料</a></li>
                            </th:block>

                            <li><a class="J_menuItem" href="../message_oa/message_frame.jsp">内部邮箱</a>
                            </li>
                            <li class="divider"></li>
                            <li><a href="../logout">安全退出</a>
                            </li>
                        </ul>
                        <script>
                            function switchRole(curRoleCode) {
                                $.ajax({
                                    type: "post",
                                    url: "../admin/switchRole.do",
                                    data: {
                                        curRoleCode: curRoleCode
                                    },
                                    dataType: "json",
                                    beforeSend: function (XMLHttpRequest) {
                                        $('body').showLoading();
                                    },
                                    success: function (data, status) {
                                        layer.msg(data.msg, {
                                            time:500,
                                            end:function () {
                                                window.location.reload();
                                            }
                                        });
                                    },
                                    complete: function (XMLHttpRequest, status) {
                                        $('body').hideLoading();
                                    },
                                    error: function () {
                                        alert(XMLHttpRequest.responseText);
                                    }
                                });
                            }
                            function switchDept(curDeptCode) {
                                $.ajax({
                                    type: "post",
                                    url: "../admin/switchDept.do",
                                    data: {
                                        curDeptCode: curDeptCode
                                    },
                                    dataType: "json",
                                    beforeSend: function (XMLHttpRequest) {
                                        $('body').showLoading();
                                    },
                                    success: function (data, status) {
                                        layer.msg(data.msg, {
                                            time:500,
                                            end:function () {
                                                window.location.reload();
                                            }
                                        });
                                    },
                                    complete: function (XMLHttpRequest, status) {
                                        $('body').hideLoading();
                                    },
                                    error: function () {
                                        alert(XMLHttpRequest.responseText);
                                    }
                                });
                            }
                        </script>
                    </div>
                    <div class="logo-element"><img src="../static/images/oa_logo.png"/>
                    </div>
                </li>
                <th:block th:utext="${tree}"></th:block>
            </ul>
        </div>
    </nav>
    <!--左侧导航结束-->
    <!--右侧部分开始-->
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header"><a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
                    <form role="search" class="navbar-form-custom" method="post" action="search_results.html">
                        <div class="form-group" th:inline="text">
                            [[${appName}]]
                        </div>
                    </form>
                </div>
                <ul class="nav navbar-top-links navbar-right">
                    <li class="hidden-xs" title="刷新">
                        <a href="javascript:;" style="padding-left:5px; padding-right:5px" onclick="refreshTabFrame()"><i class="fa fa-refresh fa-cog"></i></a>
                    </li>
                    <li class="dropdown hidden-xs">
                        <a class="right-sidebar-toggle" aria-expanded="false">
                            <i class="fa fa-tasks"></i> 主题
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
        <div class="row content-tabs">
            <button class="roll-nav roll-left J_tabLeft"><i class="fa fa-backward"></i>
            </button>
            <nav class="page-tabs J_menuTabs">
                <div class="page-tabs-content">
                    <a href="javascript:;" class="active J_menuTab" data-name="0" th:attr="data-id=${mainPage}" th:inline="text">[[${mainTitle}]]
                    </a>
                </div>
            </nav>
            <button class="roll-nav roll-right J_tabRight"><i class="fa fa-forward"></i>
            </button>
            <div class="btn-group roll-nav roll-right">
                <button class="dropdown J_tabClose" data-toggle="dropdown">关闭操作<span class="caret"></span>
                </button>
                <ul role="menu" class="dropdown-menu dropdown-menu-right">
                    <li class="J_tabShowActive"><a>定位当前选项卡</a>
                    </li>
                    <li class="divider"></li>
                    <li class="J_tabCloseAll"><a>关闭全部选项卡</a>
                    </li>
                    <li class="J_tabCloseOther"><a>关闭其他选项卡</a>
                    </li>
                </ul>
            </div>
            <a href="javascript:;" onclick="logout()" th:title="'退出 ' + ${clusterNo}" class="roll-nav roll-right J_tabExit"><i class="fa fa fa-sign-out"></i> 退出</a>
        </div>
        <div class="row J_mainContent" id="content-main">
            <iframe class="J_iframe" name="iframe0" width="100%" height="100%" th:src="@{${mainPage}}" frameborder="0" th:attr="data-id=${mainPage}" data-name="0" seamless></iframe>
        </div>
        <div class="footer">
            <div class="pull-right">&copy; 2014-2015 <a href="http://www.yimihome.com/" target="_blank">cloud web soft</a>
            </div>
        </div>
    </div>
    <!--右侧部分结束-->
    <!--右侧边栏开始-->
    <div id="right-sidebar">
        <div class="sidebar-container">
            <ul class="nav nav-tabs navs-3">
                <li class="active">
                    <a data-toggle="tab" href="#tab-1">
                        <i class="fa fa-gear"></i> 主题
                    </a>
                </li>
            </ul>

            <div class="tab-content">
                <div id="tab-1" class="tab-pane active">
                    <div class="sidebar-title">
                        <h3><i class="fa fa-comments-o"></i> 主题设置</h3>
                        <small><i class="fa fa-tim"></i> 请选择和预览主题的布局和样式，这些设置会被保存在本地，下次打开的时候会直接应用这些设置。</small>
                    </div>
                    <div class="skin-setttings">
                        <div class="title">主题设置</div>
                        <div class="setings-item" th:if="${isMenuDisplay}">
                            <span>收起左侧菜单</span>
                            <div class="switch">
                                <div class="onoffswitch">
                                    <input type="checkbox" name="collapsemenu" class="onoffswitch-checkbox" id="collapsemenu">
                                    <label class="onoffswitch-label" for="collapsemenu">
                                        <span class="onoffswitch-inner"></span>
                                        <span class="onoffswitch-switch"></span>
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="setings-item">
                            <span>固定顶部</span>
                            <div class="switch">
                                <div class="onoffswitch">
                                    <input type="checkbox" name="fixednavbar" class="onoffswitch-checkbox" id="fixednavbar">
                                    <label class="onoffswitch-label" for="fixednavbar">
                                        <span class="onoffswitch-inner"></span>
                                        <span class="onoffswitch-switch"></span>
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="setings-item">
                                <span>
                        		固定宽度
                    			</span>
                            <div class="switch">
                                <div class="onoffswitch">
                                    <input type="checkbox" name="boxedlayout" class="onoffswitch-checkbox" id="boxedlayout">
                                    <label class="onoffswitch-label" for="boxedlayout">
                                        <span class="onoffswitch-inner"></span>
                                        <span class="onoffswitch-switch"></span>
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="title">皮肤选择</div>
                        <div class="setings-item default-skin nb">
                                <span class="skin-name ">
                         <a href="#" class="s-skin-0">
                             默认皮肤
                         </a>
                    </span>
                        </div>
                        <div class="setings-item blue-skin nb">
                                <span class="skin-name ">
                        <a href="#" class="s-skin-1">
                            蓝色主题
                        </a>
                    </span>
                        </div>
                        <div class="setings-item yellow-skin nb">
                                <span class="skin-name ">
                        <a href="#" class="s-skin-3">
                            黄色/紫色主题
                        </a>
                    </span>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <!--右侧边栏结束-->
</div>
</body>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="js/plugins/layer/layer.min.js"></script>

<!-- 自定义js -->
<script src="js/hplus.js?v=4.1.0"></script>
<script type="text/javascript" src="js/contabs.js"></script>

<!-- 第三方插件 -->
<script src="js/plugins/pace/pace.min.js"></script>

<!-- Gritter -->
<link href="js/plugins/gritter/jquery.gritter.css" rel="stylesheet">
<script src="js/plugins/gritter/jquery.gritter.min.js"></script>

<script th:inline="javascript">
    [# th:if="${!isMenuDisplay}" ]
    $(function () {
        $('#page-wrapper').css("margin-left", "0px");
    });
    [/]

    function handler(msg) {
        // alert("您与服务器的连接已断开，请刷新页面尝试重新连接！");
    };

    var userName = [[${user.name}]];
    var refreshMessage = [(${refreshMessage})];

    function refreshMsg() {
        getNewMsg(userName);
        timeoutid = window.setTimeout("refreshMsg()", refreshMessage * 1000); // 每隔N秒钟刷新一次
    }

    function getNewMsg(userName) {
        $.ajax({
            type: "post",
            url: "../message_oa/getNewMsgsOfUser",
            dataType: "json",
            data: {
            },
            success: function(data, status) {
                if (data && data.length > 0) {
                    showMsgWin(data);
                }
            },
            complete: function(XMLHttpRequest, status){
            },
            error: function(XMLHttpRequest, textStatus){
                console.log(XMLHttpRequest.responseText);
            }
        });
    }

    var unique_id;

    function showMsgWin(msg) {
        var str = "";
        if (msg.length > 0) {
            var i = 0;
            for (var data in msg) {
                i++;
                var id = msg[data].id
                var title = msg[data].title;
                var sender = msg[data].sender;
                var senderPortrait = msg[data].senderPortrait;
                var type = msg[data].type;

                if (type == 10) {
                    str += "<div class=\"dropdown-messages-box\" onclick=\"addTab('" + title + "', 'message_oa/sysMessageShowPage.do?id=" + id + "')\">";
                } else {
                    str += "<div class=\"dropdown-messages-box\" onclick=\"addTab('" + title + "', 'message_oa/message_frame.jsp?id=" + id + "')\">";
                }
                str += '     <a href="javascript:;" class="pull-left">';
                str += '         <img alt="image" class="img-circle" src="../' + senderPortrait + '">';
                str += '     </a>';
                str += "     <div class=\"media-body\">";
                str += '         <small class="pull-right"></small>';
                str += '         <strong>' + msg[data].senderRealName + '</strong> ' + title;
                str += '         <br>';
                str += '         ' + msg[data].summary + '<br>';
                str += '         <small class="text-muted">' + msg[data].rq.substring(5) + '</small>';
                str += '     </div>';
                str += '</div>';
                str += '<li class="divider"></li>';

                // 最多取5条
                if (i >= 5)
                    break;
            }
        } else {
            str += '<li>';
            str += '    <div class="text-center link-block">';
            str += '            暂无新消息';
            str += '    </div>';
            str += '</li>';
            str += '<li class="divider"></li>';
        }

        str += '<li>';
        str += '    <div class="text-center link-block">';
        str += "        <a class=\"J_menuItem\" onclick=\"addTab('邮件', 'message_oa/message_frame.jsp')\">";
        str += '            <i class="fa fa-envelope"></i> <strong> 查看所有邮件</strong>';
        str += '        </a>';
        str += '    </div>';
        str += '</li>';
        str += '<li class="divider"></li>';
        str += '<li>';
        str += '    <div class="text-center link-block">';
        str += "        <a class=\"J_menuItem\" onclick=\"addTab('消息', 'message_oa/sysMessageListPage.do')\">";
        str += '            <i class="fa fa-bell"></i> <strong> 查看所有消息</strong>';
        str += '        </a>';
        str += '    </div>';
        str += '</li>';
        $('.dropdown-messages').html(str);

        if (i > 0) {
            $('.label-warning').html(i);

            unique_id = $.gritter.add({
                title: '您有' + i + '条未读信息',
                text: "请前往<a href=\"javascript:;\" onclick=\"addTab('邮件', 'message_oa/message_frame.jsp')\" class=\"text-warning\">收件箱</a>或者<a href=\"javascript:;\" onclick=\"addTab('邮件', 'message_oa/sysMessageListPage.do')\" class=\"text-warning\">消息中心</a>查看信息&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"setAllReaded()\" class=\"text-warning\">我知道了</a>",
                time: 10000
            });
        }
    }

    function setAllReaded() {
        $.ajax({
            url: "../public/message/setAllReaded.do",
            type: "post",
            data: {},
            dataType: "html",
            beforeSend: function (XMLHttpRequest) {
            },
            success: function (data, status) {
                $('.label-warning').html('');
                $.gritter.remove(unique_id, {
                    fade: true,
                    speed: 'fast'
                });
            },
            complete: function (XMLHttpRequest, status) {
            },
            error: function (XMLHttpRequest, textStatus) {
            }
        });
    }

    $(function () {
        refreshMsg();
    });

    function logout() {
        jConfirm("您确定要退出么？", "提示", function (r) {
            if (!r) {
                return;
            } else {
                window.location.href = "../logout";
            }
        });
    }
</script>
</html>
